<?php defined('SYSPATH') or die('No direct script access.');
$officefunctions = Helper_officefunctions::factory();
$thesystems      = Helper_thesystems::factory();
$mydatetime      = Helper_mydatetime::factory();
$myfunctions      = Helper_myfunctions::factory();
$display         = Helper_displayitems::factory();
$invoices_id     = Arr::get($_GET,'invoices_id');

$r = Request::current();
$action = $r->uri2();


?>
<?php $values = $officefunctions->print_invoices($invoices_id) ?>

<div id="printHeader">
<table width="1150" border="0" cellspacing="0" cellpadding="0">
	<tr>
		<td width="550" rowspan="3" align="left" valign="top">
			<table width="500" border="1" cellspacing="0" cellpadding="2">
				<tr>
					<td align="left">Ship To</td>
				</tr>
				<tr>
					<td>
					<?php echo $display->show_value($values[0]['payto'],'users','fullname') ?><br>
					<?php echo $myfunctions->format_text($display->show_value($values[0]['payto'],'users','address')) ?><br>
					<?php echo $display->show_value($values[0]['payto'],'users','city') ?> - <?php echo $display->show_value($display->show_value($values[0]['payto'],'users','country'),'countrylists') ?><br>
					<?php echo $display->show_value($values[0]['payto'],'users','phone') ?>
					</td>
				</tr>
			</table>
		</td>
		<td width="200"></td>
		<td width="230"></td>
		<td width="220" align="right">
			<table width="150" border="1" cellspacing="0" cellpadding="0">
				<tr>
					<td class="tableTitle">Invoice No.</td>
				</tr>
				<tr>
					<td class="tableContent" align="center">
						<?php echo $values[0]['invoice_code'].' '.$values[0]['invoicenumbers']; ?>
					</td>
				</tr>
			</table>
		</td>
	</tr>
	<tr align="right">
		<td height="3" colspan="3"></td>
	</tr>

	<tr align="right">
		<td></td>
		<td>
			<table width="150" border="1" cellspacing="0" cellpadding="0">
				<tr>
					<td class="tableTitle">Invoice Date</td>
				</tr>
				<tr>
					<td class="tableContent" align="center"><?php echo $mydatetime->mktime_from_sql($values[0]['datetime'],'d-M-Y'); ?></td>
				</tr>
			</table>
		</td>
		<td>
			<table width="200" border="1" cellspacing="0" cellpadding="0">
				<tr>
					<td class="tableTitle">Payment Terms</td>
				</tr>
				<tr>
					<td class="tableContent" align="center"><?php echo $mydatetime->date_addition($values[0]['datetime'],'+1 month','d-M-Y'); ?></td>
				</tr>
			</table>
		</td>
	</tr>
</table>
</div>
<?php //$transactionarrays = $invoicefunctions->invoice_transaction($invoice_id); ?>
<div class="printContent">
<table width="1150" border="1" cellspacing="0" cellpadding="3" align="center">
	<tr align="center" class="tableTitle">
		<td width="50">No.</td>
		<td width="130">Code</td>
		<td width="501">Item</td>
		<td width="70">Qty.</td>
		<td width="160">Unit Price</td>
		<td width="160">Amount</td>
	</tr>
<?php if(empty($values)) { ?>
	<tr align="center" valign="top" class="tableContent">
		<td colspan="7">No Transaction Data</td>
	</tr>
<?php } ?>
	
	<?php 
		$number = 1; 
		$total_subtotal = 0;
	?>

	<?php foreach($values as $value) { ?>

	<?php  
		$totalitems         =	$value['totalitems'];
		$ammounts           = $value['ammounts'];
		$item_kali_ammounts =  $totalitems * $ammounts;
		$subtotal           = $item_kali_ammounts;
		$total_subtotal     += $subtotal;
	?>
	<tr align="center" valign="top" class="tableContent">
		<td><?php echo $number; ?></td>
		<td><?php echo $display->show_value($value['items'],'products','code') ?></td>
		<td align="left">
		<?php echo $display->show_value($value['items'],'products','name') ?>
		</td>
		<td><?php echo $totalitems ?></td>
		<td align="right"><?php echo number_format($ammounts); ?></td>
		<td align="right"><?php echo number_format($subtotal); ?></td>
	</tr>
	<?php $number++; ?>
	<?php } ?>
</table>
</div>

<div class="printFooter">
<table width="1150" border="0" cellspacing="0" cellpadding="0">
	<tr align="left">
		<td width="325">
			<table width="200" border="0" cellspacing="1" cellpadding="0">
				<tr align="left">
					<td>Prepared by :</td>
				</tr>
				<tr align="left">
					<td height="80" style="border-bottom: 1px solid #000;">&nbsp;</td>
				</tr>
				<tr align="left">
					<td>
					<?php echo $display->show_value($values[0]['users_id'],'users','fullname'); ?><br>
					Date :
					</td>
				</tr>
			</table>
		</td>
		<td width="325">
			<table width="200" border="0" cellspacing="1" cellpadding="0">
				<tr align="left">
					<td>Recieved by :</td>
				</tr>
				<tr align="left">
					<td height="80" style="border-bottom: 1px solid #000;">&nbsp;</td>
				</tr>
				<tr align="left">
					<td>Date :</td>
				</tr>
			</table>
		</td>
		<td width="500" align="right" valign="top">
			<table width="400" border="0" cellspacing="1" cellpadding="0" align="right">
				<tr align="right">
					<td width="370">Sub Total</td>
					<td width="7">:&nbsp;</td>
					<td width="210">Rp.<?php echo number_format($total_subtotal); ?>,-</td>
				</tr>
				
			</table>
		</td>
	</tr>
</table>
</div>
  








